#ifndef VOLUMEREADER_H
#define VOLUMEREADER_H

#include <QObject>
#include <QString>
#include <QByteArray>

#include <windows.h>
#include <exception>

#include "utils.h"
#include "NTFSBootSector.h"
#include "CMFT.h"

class CMFT;
class MemoryBuffer;
class VolumeReader : public QObject
{
	Q_OBJECT

public:
	//drive name must be of the pattern \\.\c:
	VolumeReader(QString volumePath, QObject *parent = 0);
	~VolumeReader();
	bool isReady();
	QString getError();
	const QByteArray read(UINT64 start,UINT64 len) ;
	void read(UINT64 start,UINT64 len,char * target) const ;
	void SetupFSInfo();
	void errorClose( QString errStr, QString file = __FILE__,int line =__LINE__);
// 	bool isFat32();
// 	QList<PrettyDirEntry> allFiles();
// 	QList<PrettyDirEntry> allDeletedFiles();
// 	UINT64 size();
// 	QByteArray GetCluster( UINT32 RootCluster );
// 	UINT32 ClusterToSector( int cluster );
// 	
// 	QByteArray GetFileByCluster( int clusterIndex );
// 	int GetNextClusterIndex( int curCluster ) ;
// 	QVector<UINT32> allClusters(int startC) ;
// 	void scanDeleted();

	HANDLE hVol;
	QString _errStr;
	QString _errFile;
	int _errLine;
	//QList<PrettyDirEntry> allChildFiles(int clusterIndex,int fatherDE = -1,bool bDeleted = false);
	NTFSBootSector *bootSect;
	CMFT masterMFT;
	inline UINT64 C2Byte(UINT64 cluster) {
		return cluster*bootSect->SectorPerCluster*bootSect->BytesPerSector;
	}
	CMFT MFTEntry(int entry);
public :
	CMFT MFTAt( UINT64 StartByte );
	UINT64 volumeSize();
	bool isMFT( UINT64 startByte );
	UINT64 clusterSize();
	UINT64 getEntryNo( UINT64 diskOffSet );

	MemoryBuffer *m_buffer;
};

#endif // VOLUMEREADER_H
